// components/search/search.js
import Api from '../../utils/Api';
import Config from '../../utils/Config';

Component({
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        mySearch:[],
        hotSearch:[],
        searchText:''
    },

    /**
     * 组件的方法列表
     */
    methods: {
        getSearchData(){
            this.getHotSearch();
            this.getMySearch();
        },
        goSearch(e){
            let searchText = this.data.searchText;
            // 跳转至搜索列表页 recipeList
            wx.navigateTo({
              url: '../../pages/recipeList/recipeList?type=search&searchText='+searchText
            });
        },
        // 点击关键字sous
        tapSearch(e){
            let searchText = e.currentTarget.dataset.searchText;
            // 跳转搜索
            wx.navigateTo({
                url: '../../pages/recipeList/recipeList?type=search&searchText='+searchText
              });

        },
        // 获取热门搜索
        async getHotSearch(){
            let hotSearch = (await (wx.cloud.callFunction({
                name:'getLimitData',
                data:{
                    tableName:Config.tableName.searchKeywordsTable,
                    skip:0,
                    limit:9,
                    sort:{
                        searchCount:-1,
                        searchDate:-1
                    }
                }
            }))).result.list;
            this.setData({hotSearch});
        },
        // 获取本地历史搜索
        getMySearch(){
            let mySearch = wx.getStorageSync('mySearch');
            mySearch = mySearch?mySearch:[];
            this.setData({
                mySearch
            })
        },
        bdinp(){}
    }
})
